package org.jb.coinche.client.business.model;

import java.util.HashMap;
import java.util.Map;

import org.jb.coinche.client.guistatemachine.AbstractState;


public class AuctionTurn extends AbstractState implements GameState {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1788839179779616347L;
	/**
	 * @param currentAuction the currentAuction to set
	 */
	public void setCurrentAuction(Auction currentAuction) {
		this.currentAuction = currentAuction;
	}
	
	/**
	 * @return the currentAuction
	 */
	public Auction getCurrentAuction() {
		return currentAuction;
	}
	
	/**
	 * @param waitingPlayer the waitingPlayer to set
	 */
	public void setWaitingPlayer(Player waitingPlayer) {
		this.waitingPlayer = waitingPlayer;
	}
	/**
	 * @return the waitingPlayer
	 */
	public Player getWaitingPlayer() {
		return waitingPlayer;
	}

	/**
	 * @param game the game to set
	 */
	public void setGame(Game game) {
		this.game = game;
	}
	
	/**
	 * @return the game
	 */
	public Game getGame() {
		return game;
	}

	/**
	 * 
	 */
	public void setAuction( Player u, Auction auction ) {
		if (auction == null) {
			noauctioncount++;
			
			Auction auctionmock = new Auction();
			mapAuctions.put(u, auctionmock );
		} else {
			noauctioncount = 0;
			
			currentAuction = new Auction();
			currentAuction.setPlayer( u );
			currentAuction.setTrump( auction.getTrump() );
			currentAuction.setValue( auction.getValue() );
			
			mapAuctions.put(u, auction );
		}
	}
	
	/**
	 * 
	 * @param p
	 * @return
	 */
	public Auction getPlayerAuction( Player p ) {
		return mapAuctions.get( p );
	}
	
	/**
	 * @return the noauctioncount
	 */
	public boolean isFinished() {
		return currentAuction == null ? noauctioncount == 4 : noauctioncount == 3;
	}

	private Map< Player, Auction > mapAuctions = new HashMap< Player, Auction >();
	
	private Auction currentAuction;
	private Player waitingPlayer;
	private int noauctioncount = 0;
	private Game game;
}
